<template>
    <div>
        <h1>房价信息显示</h1>
        <hr>
        <a href="/RAdd">房价信息新增</a>
        <hr>
        <a href="https://localhost:7206/api/RoomPrice/Dao">导出</a>
        <hr>
        <a href="/NShow">房号信息显示</a>
        <hr>
        


        <table class="table">
            <thead>
                <tr>
                    <td>房价编号</td>
                    <td>房间价格</td>
                    <td>最大人数</td>
                    <td>房间类型</td>
                    <td>房间状态</td>
                    <td>是否出售</td>
                    <td>操作</td>
                </tr>
            </thead>
            <tbody>
                <tr v-for="a in data">
                    <td>{{a.Id}}</td>
                    <td>{{a.Price}}</td>
                    <td>{{a.Num}}</td>
                    <td>{{a.Name}}</td>
                    <td>{{a.State?"开放":"维修"}}</td>
                    <td>{{a.CState?"已出售":"未出售"}}</td>
                    <td>
                        <input type="button" value="修改" @click="Upd(a.Id)">
                    </td>
                </tr>
            </tbody>
        </table>

一共{{page.zys}}页，一共{{page.zhs}}行，第{{cha.Pageindex}}页，每页{{cha.Pagesize}}行

        <input type="button" value="首页" @click="fy(1)">
        <input type="button" value="上一页" @click="fy(2)">
        <input type="button" v-for="a in page.zys" :value="a" @click="ym(a)">
        <input type="button" value="下一页" @click="fy(3)">
        <input type="button" value="尾页" @click="fy(4)">
        页容量：
        <select v-model="cha.Pagesize" @click="yrl">
            <option value="2">请选择</option>
            <option value="3">3</option>
            <option value="5">5</option>
            <option value="7">7</option>
            <option value="10">10</option>
        </select>    
        <input type="text" v-model="cha.Pageindex"><input type="button" value="跳转" @click="tz">
        
    </div>
</template>

<script setup lang="ts">

import { ref,onMounted } from 'vue';
import axios from 'axios';
import { useRouter } from 'vue-router';
import RUpd from './RUpd.vue';

onMounted(()=>{
    HShow()
})
const yrl = ()=>{
    HShow()
}
const ym = (val:any)=>{
    cha.value.Pageindex=val
    HShow()
}
const tz = ()=>{
    HShow()
}
const data = ref([{
    "Id": 1,
      "Price": "138",
      "Num": 77,
      "State": true,
      "CState": true,
      "TId": 1,
      "Name": "毛坯房"
}])
const cha = ref({
    Pageindex:1,
    Pagesize:2,

})
const page = ref({
    zys:0,
    zhs:0
})


const fy = (e:any)=>{
    if(e==1){
        cha.value.Pageindex=1;
        HShow()
    }

    if(e==2){
        if(cha.value.Pageindex>1){
            cha.value.Pageindex-=1;
            HShow()
        }
    }

    if(e==3){
        if(cha.value.Pageindex<page.value.zys){
            cha.value.Pageindex+=1;
            HShow();
        }
    }


    if(e==4){
        cha.value.Pageindex = page.value.zys;
        HShow()
    }
}
const router = useRouter()
const HShow = ()=>{
    axios.get('https://localhost:7206/api/RoomPrice/RShow',{params:cha.value}).then(res=>{
        data.value = res.data.list;
        page.value.zhs = res.data.count;
        page.value.zys = Math.ceil(page.value.zhs/cha.value.Pagesize)
    })
}
//反填
const Upd=(e:any)=>{
    router.push({path:"/RUpd",query:{Id:e}});
}



</script>

<style scoped>

</style>